﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GUI;
using GUI.UsersControls;

namespace GUI.UserControls
{
    public partial class Menu : UserControl
    {
        private Color couleurActive;
        private Color couleurSemiActive;
        private Color couleurInactive;
        private MenuOnglet _menuOnglet;
        private Onglet[] _onglets;
        private UcPanel.ongletIndex _indexOnglet;
        private int _ongletEnCours;

        public Menu()
        {
            InitializeComponent();
            couleurActive = Color.FromArgb(40, 82, 145);
            couleurSemiActive = Color.FromArgb(74, 74, 74);
            couleurInactive = Color.Black;
            _ongletEnCours = 0;
            String[] _mmm = new String[5];
            _onglets = new Onglet[4];            
            _onglets[0].nom = "Les Produits";
            _onglets[0].boutons = new String[5] {"Les Produits", "Les Besoins", "Les Cas d'utilisations", "Les Fonctionnalitées","Les Tâches"};            
            _onglets[1].nom = "Etude et Développement";
            _onglets[1].boutons = new String[5] {"Créer les Tâches", "Le Planning", "Le SAH", "Les Ressources",""};            
            _onglets[2].nom = "Maintenance";
            _onglets[2].boutons = new String[5] {"Les Anomalies","Le Planning","","",""};            
            _onglets[3].nom = "Options";
            _onglets[3].boutons = new String[5] {"Option de base","Aide","","",""};
        }

        struct Onglet
        {
            public String nom;
            public String[] boutons;
        }

        public UcPanel.ongletIndex indexOnglet
        {
            get { return _indexOnglet; }
            set
            {
                _indexOnglet = value;
                cacher();
            }
        }

        public void Init()
        {
            _menuOnglet = new MenuOnglet();
            _menuOnglet.Location = new Point(0, this.Location.Y + this.Size.Height);
            _menuOnglet.Visible = false;
            _menuOnglet.Init(this);
            Parent.Controls.Add(_menuOnglet);
        }

        public void recevoirClickSurMenuOnglet(String texte)
        {
            _menuOnglet.Visible = false;
            if (texte == "Les Produits")
            {
                ((FormMain)this.Parent).afficherLesProduits();
                return;
            }
            if (texte == "Les Besoins")
            {
                ((FormMain)this.Parent).afficherLesBesoins();
                return;
            }
            if (texte == "Les Cas d'utilisations")
            {
                ((FormMain)this.Parent).afficherLesCasUtilisations();
                return;
            }
            if (texte == "Les Fonctionnalitées")
            {
                ((FormMain)this.Parent).afficherLesFonctionnalites();
                return;
            }
            if (texte == "Les Tâches")
            {
                ((FormMain)this.Parent).afficherLesTaches();
                return;
            }
            if (texte == "Créer les Tâches")
            {
                ((FormMain)this.Parent).afficherCreerLesTaches();
                return;
            }
            if (texte == "Le Planning")
            {
                ((FormMain)this.Parent).afficherLePlanning();
                return;
            }
            if (texte == "Le SAH")
            {
                ((FormMain)this.Parent).afficherLeSAH();
                return;
            }
            if (texte == "Les Ressources")
            {
                ((FormMain)this.Parent).afficherLesRessources();
                return;
            }
            if (texte == "Les Anomalies")
            {
                ((FormMain)this.Parent).afficherLesMaintenance();
                return;
            }
            if (texte == "Le Planning des Anomalies")
            {
                ((FormMain)this.Parent).afficherLePlanningMaintenance();
                return;
            }
            if (texte == "Option de base")
            {
                ((FormMain)this.Parent).afficherLesOptions();
                return;
            }
            if (texte == "Aide")
            {
                ((FormMain)this.Parent).afficherLAide();
                return;
            }
        }

        private void btnHome_MouseEnter(object sender, EventArgs e)
        {
            btnHome.BackgroundImage = global::GUI.Properties.Resources.Home2; 
        }

        private void btnHome_MouseLeave(object sender, EventArgs e)
        {
            btnHome.BackgroundImage = global::GUI.Properties.Resources.Home; 
        }

        private void btnMenu_Click(object sender, EventArgs e)
        {
            int boutonSender = ((Control)sender).TabIndex;
            if (_ongletEnCours == boutonSender)
                cacher(((Control)sender));
            else
            {
                afficher(((Control)sender));
            }
        }

        private void cacher(Control btnSender = null)
        {
            if (_menuOnglet != null)
                _menuOnglet.Visible = false;
            _ongletEnCours = 0;
            btnMenu1.BackColor = couleurInactive;
            btnMenu2.BackColor = couleurInactive;
            btnMenu3.BackColor = couleurInactive;
            btnMenu4.BackColor = couleurInactive;
            prendreEnComptePanelEnCours();
            if (btnSender != null && ((int)_indexOnglet) != btnSender.TabIndex)
                btnSender.BackColor = couleurSemiActive;
        }

        private void afficher(Control leControl)
        {
            btnMenu1.BackColor = couleurInactive;
            btnMenu2.BackColor = couleurInactive;
            btnMenu3.BackColor = couleurInactive;
            btnMenu4.BackColor = couleurInactive;
            _ongletEnCours = leControl.TabIndex;
            _menuOnglet.charger(_onglets[_ongletEnCours - 1].boutons);
            _menuOnglet.Visible = true;
            _menuOnglet.BringToFront();
            leControl.BackColor = couleurActive;
            prendreEnComptePanelEnCours();
        }

        private void prendreEnComptePanelEnCours()
        {
            switch (_indexOnglet)
            {
                case UsersControls.UcPanel.ongletIndex.BESOINS:
                    btnMenu1.BackColor = couleurActive;
                    return;
                case UsersControls.UcPanel.ongletIndex.ETUDES:
                    btnMenu2.BackColor = couleurActive;
                    return;
            }
        }

        private void btnMenu_MouseEnter(object sender, EventArgs e)
        {
            if (((Control)sender).BackColor == couleurInactive)
                ((Control)sender).BackColor = couleurSemiActive;
        }

        private void btnMenu_MouseLeave(object sender, EventArgs e)
        {
            if (((Control)sender).BackColor == couleurSemiActive)
                ((Control)sender).BackColor = couleurInactive;
        }

        private void btnHome_Click(object sender, EventArgs e)
        {
            ((FormMain)this.Parent).afficherAccueil();
        }
    }
}
